#include <iostream>
#include <list>
#include "Card.h"
#include <conio.h>
#include "OrderObject.h"
#include "CardWOrderStk.h"
#include <stack>

using namespace std;
typedef list<Card> CardList;
void showList(CardList &myList);
void insert(CardList &myList, Card x);
bool remove(CardList &myList, Card x);
bool removeAll(CardList &myList, Card x);
char turnIntIntoVal(int k);
Card::Suit turnIntIntoSuit(int k);
Card generateRandomCard(bool fixedSequence);

// main method ---------------------------------------
/*
int main()
{
   CardList myList;
   int k;
   Card x,y;
   // build list of 10 floats, 2 at a time (1 random and 1 k*100)
   // throw some duplicates in

		x = generateRandomCard(true);
		y = generateRandomCard(true);
		insert(myList, x);
		insert(myList, y);

		remove(myList, y);
		showList(myList);
   // should be sorted
  
   //cout << "\nafter removal:" << endl;
   //showList(myList);
   //if (!remove(myList, -10)) // should have no effect
   //   cout << " -10 not in list as expected. ";
   getch();

   return 0;
}
*/
int main()
{
	char valueOrder[] = {'3', '4', '5', '6', '7', '8', '9', 'T', 'J',
      'Q', 'K', 'A', '2'};
    Card::Suit suitOrder[] = {Card::diamonds, Card::clubs,
      Card::hearts, Card::spades};
   
	getch();
	return 0;
}
// Global method definitions --------------------------
void insert(CardList &myList, Card x)
{
   list<Card>::iterator iter;
   // loop until we find a float > x
   for (iter = myList.begin() ; iter != myList.end() ; iter++ )
   {
	   if (x.compareTo(*iter) == 0)
         break; // found the exact place for this float
   }
   myList.insert(iter, x);
}

bool remove(CardList &myList, Card x)
{
   bool result = false;
	list<Card>::iterator iter;
	for (iter = myList.begin() ; iter != myList.end();)
	{
		if (x.compareTo(*iter) == 0)
		{
			myList.erase(iter);
			result = true;
		}
		else
			++iter;
	}
	return result;
}

bool removeAll(CardList &myList, Card x)
{
	bool result = false;
	list<Card>::iterator iter;
	for (iter = myList.begin() ; iter != myList.end() ; iter++ )
	{
		if (x.compareTo(*iter) == 0)
		{
			result = true;
		}
		myList.erase(iter);
	}
	return result;
}

void showList(CardList &myList)
{
   list<Card>::iterator iter;
   cout << endl << "_____Here's the Card List_______" << endl;
   for( iter = myList.begin(); iter != myList.end(); iter++)
   {
      cout.setf(ios::fixed);
      cout.precision(3);
	  cout << iter->getSuit() << " " << iter->getVal() << endl;
   }
   cout << endl << "_____That's all!_______" << endl << endl;
}

Card::Suit turnIntIntoSuit(int k)
{
   return (Card::Suit) k;  //
}

char turnIntIntoVal(int k)
{
   k++; // put in range 1-13
   switch(k)
   {
   case 1:
      return 'A';
   case 10:
      return 'T';
   case 11:
      return 'J';
   case 12:
      return 'Q';
   case 13:
      return 'K';
   default:
      return '0' + k;   // simple way to turn n into 'n'
   }
}

Card generateRandomCard(bool fixedSequence)
{
   // if param = true, use clock to seed, otherwise, fixed seed for debugging
   static bool firstTime = true;
   Card::Suit suit;
   char val;

   int suitSelector, valSelector;

   // only do seed on first call, ever
   if (firstTime)
   {
      firstTime = false;
      if (fixedSequence)
         srand(1);
      else
         srand(time(NULL));
   }

   // get random suit and value
   suitSelector = rand() % 4;
   valSelector = rand() % 13;

   // pick suit
   suit = turnIntIntoSuit(suitSelector);
   val = turnIntIntoVal(valSelector);

   return Card(val, suit);
}